package org.csu.wuliu.service;

import org.csu.wuliu.domain.Task;
import org.csu.wuliu.persistence.TaskMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class TaskService {
    @Autowired
    private TaskMapper taskMapper;

    public Task getTaskByTaskId(String taskId){
        return taskMapper.getTaskByTaskId(taskId);
    }

    public Task getTaskByOrderId(String orderId){
        return taskMapper.getTaskByOrderId(orderId);
    }

    public List<Task> getTaskListByDistributorId(String distributorId){
        return  taskMapper.getTaskListByDistributorId(distributorId);
    }

    public List<Task> getTaskListByUsername(String username){
        return taskMapper.getTaskListByUsername(username);
    }

    public List<Task> getTaskListBySubstationAndStatus(String substationId,int status){
        return taskMapper.getTaskListBySubstationAndStatus(substationId,status);
    }

    public void insertTask(Task task){
        taskMapper.insertTask(task);
    }

    public void updateTask(Task task){
        taskMapper.updateTask(task);
    }

    //根据订单号自动生成对应任务单
    public void autoCreated(String orderId){
        Task task = new Task();
        String taskId = "TS"+ orderId.substring(2);
        task.setOrderId(orderId);
        task.setTaskId(taskId);
        task.setStatus(0);
        insertTask(task);
    }

    public List<String> getLeastTaskSub(){
        return taskMapper.getLeastTaskSub();
    }



}
